import { encrypt, decrypt } from "crypto-js/aes";
import UTF8, { parse } from 'crypto-js/enc-utf8';
import pkcs7 from 'crypto-js/pad-pkcs7';
import ECB from 'crypto-js/mode-ecb';
export class AesEncrypting {
  #key;
  #iv;

  constructor(option) {
    this.#key = option.key;
    this.#iv = option.iv;
  }
  get getOptions() {
    return {
      mode: ECB,
      padding: pkcs7,
      iv: this.#iv,
    };
  }

  //加密
  encryptByAES(cipherText) {
    return encrypt(cipherText, this.#key, this.getOptions).toString();
  }
  //解密
  decryptByAES(cipherText) {
    return decrypt(cipherText, this.#key, this.getOptions).toString(UTF8);
  }
}
